﻿using System.Collections.Generic;
using System.Linq;

namespace PengSW.Utility
{
    public class Pair<T1, T2>
    {
        public Pair() { }
        public Pair(T1 t1, T2 t2)
        {
            First = t1;
            Second = t2;
        }
        public Pair(Pair<T1, T2> aPair)
        {
            First = aPair.First;
            Second = aPair.Second;
        }
        public T1 First { get; set; }
        public T2 Second { get; set; }
    }

    public class PairList<T1, T2> : List<Pair<T1, T2>>
    {
        public void Add(T1 t1, T2 t2)
        {
            this.Add(new Pair<T1, T2>(t1, t2));
        }

        public Pair<T1, T2> GetByFirst(T1 aFirst)
        {
            return (from r in this where object.Equals(r.First, aFirst) select r).FirstOrDefault();
        }
        public Pair<T1, T2> GetBySecond(T2 aSecond)
        {
            return (from r in this where object.Equals(r.Second, aSecond) select r).FirstOrDefault();
        }
    }
}
